package com.micangcaihang.micang.mvp.task.ui;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.micangcaihang.common.base.activity.BaseActivity;
import com.micangcaihang.common.widget.titlebar.TitleBar;
import com.micangcaihang.micang.R;
import com.micangcaihang.micang.databinding.ActivityDeliveryDBinding;
import com.micangcaihang.micang.mvp.task.presenter.DDeliveryPresenter;

/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayongfly@gmail.com
 *     time   : 2017/07/25
 *     update : 2017/07/25
 *     desc   : 调评预览
 *     version: 1.0
 * </pre>
 */

public class DDeliveryActivity extends BaseActivity<DDeliveryPresenter, ActivityDeliveryDBinding> {

    /**
     * 获取资源文件布局
     *
     * @return 资源布局文件layout
     */
    @Override
    protected int getLayoutId() {
        return R.layout.activity_delivery_d;
    }

    /**
     * 获取传递的bundle数据
     *
     * @param extras
     */
    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    public void initView() {
        super.initView();

    }

    @Override
    protected void initData() {
        super.initData();
    }


    /**
     * 初始化按钮监听
     */
    @Override
    protected void initListener() {
        mViewBinding.includeTuftInfo.setClickHadnler(new CilckHandler());
        mViewBinding.includeTuftMating.setClickHadnler(new CilckHandler());
        mViewBinding.includeWayStatus.setClickHadnler(new CilckHandler());
        mViewBinding.includeRimMating.setClickHadnler(new CilckHandler());
        mViewBinding.includeLandInfo.setClickHadnler(new CilckHandler());
        mViewBinding.titleBar.setDelegate(new TitleBar.Delegate() {
            @Override
            public void onClickLeftCtv() {
                finish();
            }

            @Override
            public void onClickTitleCtv() {

            }

            @Override
            public void onClickRightCtv() {

            }

            @Override
            public void onClickRightSecondaryCtv() {

            }
        });
    }

    private void setExpandDrawable(TextView view, boolean isExpand) {
        Drawable drawable;
        if (isExpand) {
            drawable = mContext.getResources().getDrawable(R.drawable.ic_expand);
        } else {
            drawable = mContext.getResources().getDrawable(R.drawable.ic_collapse);
        }

        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());//必须设置图片大小，否则不显示

        view.setCompoundDrawables(null, null, drawable, null);
    }

    public class CilckHandler {
        public void onTuftInfo(View view) {
            if (mViewBinding.includeTuftInfo.expandableLayoutTuftInfo.isExpanded()) {
                mViewBinding.includeTuftInfo.expandableLayoutTuftInfo.collapse();
                setExpandDrawable(mViewBinding.includeTuftInfo.tvTuftInfo, true);
            } else {
                mViewBinding.includeTuftInfo.expandableLayoutTuftInfo.expand();
                setExpandDrawable(mViewBinding.includeTuftInfo.tvTuftInfo, false);
            }
        }

        public void onTuftMating(View view) {
            if (mViewBinding.includeTuftMating.expandableLayoutTuftMating.isExpanded()) {
                mViewBinding.includeTuftMating.expandableLayoutTuftMating.collapse();
                setExpandDrawable(mViewBinding.includeTuftMating.tvTuftMating, true);

            } else {
                mViewBinding.includeTuftMating.expandableLayoutTuftMating.expand();
                setExpandDrawable(mViewBinding.includeTuftMating.tvTuftMating, false);

            }
        }

        public void onWayStatus(View view) {
            if (mViewBinding.includeWayStatus.expandableLayoutWayStatus.isExpanded()) {
                mViewBinding.includeWayStatus.expandableLayoutWayStatus.collapse();
                setExpandDrawable(mViewBinding.includeWayStatus.tvWayStatus, true);

            } else {
                mViewBinding.includeWayStatus.expandableLayoutWayStatus.expand();
                setExpandDrawable(mViewBinding.includeWayStatus.tvWayStatus, false);

            }
        }

        public void onRimMating(View view) {
            if (mViewBinding.includeRimMating.expandableLayoutRimMating.isExpanded()) {
                mViewBinding.includeRimMating.expandableLayoutRimMating.collapse();
                setExpandDrawable(mViewBinding.includeRimMating.tvRimMating, true);

            } else {
                mViewBinding.includeRimMating.expandableLayoutRimMating.expand();
                setExpandDrawable(mViewBinding.includeRimMating.tvRimMating, false);

            }
        }

        public void onLandInfo(View view) {
            if (mViewBinding.includeLandInfo.expandableLayoutLandInfo.isExpanded()) {
                mViewBinding.includeLandInfo.expandableLayoutLandInfo.collapse();
                setExpandDrawable(mViewBinding.includeLandInfo.tvLandInfo, true);

            } else {
                mViewBinding.includeLandInfo.expandableLayoutLandInfo.expand();
                setExpandDrawable(mViewBinding.includeLandInfo.tvLandInfo, false);

            }
        }

        public void onPriceSurvey(View view) {

        }

        public void onAssessResult(View view) {

        }
    }
}
